//index.js
//获取应用实例
const app = getApp()
// const Api = require("../../utils/api.js").API
// const Store = require("../../utils/store.js").store
// const codeZ = require("../../utils/util.js")
Page({
    data: {
       
    },
    onLoad() {
       
    },
    onShow: function() {
      
     
    },
    zhifu:function(){
       
      
        let that = this;
        wx.chooseMessageFile({
          count: 10,
          type: 'file',
          success (res) {
              console.log(res);
            // tempFilePath可以作为img标签的src属性显示图片
            const tempFilePaths = res.tempFiles
            that.uploadExcel(res.tempFiles[0].path);
          }
        })
        // wx.navigateTo({
        //     url: '../MyExcelSave/index',
        // })
    },
    uploadExcel(path){
        wx.showLoading();
        let that =this;
        wx.cloud.uploadFile({
            cloudPath:'New.xls',
            filePath:path,
            success:res=>{
                console.log('上传成功',res.fileID)
                that.jiexi(res.fileID)
            },fail:err=>{
                 wx.hideLoading();
                wx.showToast({
                    title: '请确认Excel数据上传失败!',
                    icon: 'none',
                    duration: 2000
                })
                // console.log('上传失败',err);
            }
        })
        
    },
    jiexi(fileID){
        wx.cloud.callFunction({
            name:'excel',
            data:{
                fileID:fileID
            },
            success:res=>{
                  wx.hideLoading();
                var a = JSON.stringify(res.result.arr);
                wx.showToast({
                    title:'解析成功!',
                    icon: 'none',
                    duration: 1500
                })
                setTimeout(function () {  
                    wx.navigateTo({
                        url:'../MyExcelSave/index?item='+a
                    })
                    }, 2000)
                  // console.log('解析成功',res)
              
              
                
               
                
            },fail:err=>{
                  wx.hideLoading();
                wx.showToast({
                    title: '请确认Excel数据,解析失败!',
                    icon: 'none',
                    duration: 2000
                })
                // console.log('解析失败',err);
            }
            
        })
    },
    
    
   
   

  
    

});
